package com.lznAdmin.system.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.assertj.core.util.Lists;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @program: lzn-manage-parent
 * @description:
 * @author: lzn
 * @create: 2021-09-02 12:16
 **/
@Data
@TableName(value = "sys_role")
public class SysRole implements Serializable {

    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 角色名称
     */
    private String name;

    /**
     * 角色描述
     */
    private String remark;


    private Date createDate;

    private Date updateDate;

    private Integer deleted;

    /**
     * 排序
     */
    @OrderBy(asc = true)
    private Double sortNum;

    /**
     * 存储当前角色的权限资源对象集合
     * 修改角色时用到
     */
    @TableField(exist = false)
    private List<SysPermission> perList = Lists.newArrayList();

    /**
     * 存储当前角色的权限资源ID集合
     * 修改角色时用到
     */
    @TableField(exist = false)
    private List<Long> perIds = Lists.newArrayList();

    public List<Long> getPerIds() {
        if (CollectionUtils.isNotEmpty(perList)) {
            perIds = Lists.newArrayList();
            for (SysPermission per : perList) {
                perIds.add(per.getId());
            }
        }
        return perIds;
    }
}
